package by.grsu.epam.service;

import java.io.Serializable;
import java.util.List;

import org.hibernate.criterion.Criterion;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import by.grsu.epam.dao.GenericDAO;

@Service
public abstract class GenericServiceImpl<T, PK extends Serializable> implements GenericService<T, PK> {
	
	public abstract GenericDAO<T, PK> getDAO();

	@Override
	@Transactional
	public PK save(T newInstance) {
		return (PK) getDAO().save(newInstance);
	}

	@Override
	@Transactional
	public void update(T transientObject) {
		getDAO().update(transientObject);
	}

	@Override
	@Transactional
	public List<T> findAll() {
		return (List<T>) getDAO().findAll();
	}

	@Override
	@Transactional
	public List<T> findByCriteria(Criterion... criterion) {
		return (List<T>) getDAO().findByCriteria(criterion);
	}

	@Override
	@Transactional
	public T findById(PK id) {
		return (T) getDAO().findById(id);
	}

	@Override
	@Transactional
	public void delete(PK id) {
		getDAO().delete(id);
	}

	@Override
	@Transactional
	public void delete(T persistantObject) {
		getDAO().delete(persistantObject);
	}

}
